package cn.java.compare;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 小石潭记
 * @date 2021/7/27 14:22
 * @Description: ${todo}
 */
public class Test {
    private static final List<User> users = new ArrayList<User>() {
        {
            add(new User(1, "小明", 18,"北京", LocalDate.now()));
            add(new User(2, "小黄", 19,"北京西", LocalDate.now().plusDays(-1)));
            add(new User(3, "小刘", 15,"北京西部", LocalDate.now().plusDays(2)));
            add(new User(4, "小王", 36,"北京南部", LocalDate.now().plusDays(1)));
        }
    };

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class User {
        private int id;
        private String name;
        private int age;
        private String address;
        private LocalDate birthday;
    }

    public static void main(String[] args) {
        Collections.sort(users, (u1, u2) -> {
            String address1 = u1.getAddress();
            String address2 = u2.getAddress();
            return address1.compareTo(address2);
        });
        System.out.println(users);

        Collections.sort(users, (u1, u2) -> {
            Integer age1 = u1.getAge();
            Integer age2 = u2.getAge();
            return age2.compareTo(age1);
        });
        System.out.println(users);
    }
}
